package com.intermancer.predictor.feeder;

import org.testng.AssertJUnit;

import com.intermancer.predictor.audit.Counter;
import com.intermancer.predictor.data.ConsumeResponse;
import com.intermancer.predictor.data.Quantum;

public class HungryCountFCL implements FeedCycleListener, Counter {

	private int threshold;
	private int count;
	
	public HungryCountFCL() {
	}

	public HungryCountFCL(int threshold) {
		this.threshold = threshold;
	}

	public void init() {
		count = 0;
	}

	public boolean handle(ConsumeResponse consumeResponse,
			Quantum quantum) {
		count++;
		boolean shouldBeHungry = count < threshold;
		boolean isNotHungry = consumeResponse.getStatus() != ConsumeResponse.HUNGRY_STATUS_VALUE;
		boolean shouldBeComplete = count >= threshold;
		boolean isNotComplete = !ConsumeResponse.CONSUME_COMPLETE.equals(consumeResponse);
		
		AssertJUnit.assertFalse((shouldBeHungry && isNotHungry) || (shouldBeComplete && isNotComplete));
		return true;
	}

	public int getThreshold() {
		return threshold;
	}

	public void setThreshold(int threshold) {
		this.threshold = threshold;
	}

	public int getCount() {
		return count;
	}

}
